<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
    String path = request.getContextPath(); 
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+path+ "/"; 
%>
<!DOCTYPE HTML>
<html>
<head>
	<base href="<%=basePath%>">
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<title>职位权限管理</title>
	<link rel="stylesheet" href="plugin/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="plugin/bootstrap-table/dist/bootstrap-table.css">
<style type="text/css">
 
  .addbr{
     float: right;
    margin-right: 80px;
  }
  .pad{
    padding-left:15px;
    padding-top:10px;
  }
  .im{
     padding:10px;
  }
  .padtr{
      margin-top:5px;
  }
  #filediv{
  border: 2px solid #ccc6c6;
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    display: inline-block;
    margin-right: 20px;
  }

.btn1{
    margin-top: 10px;
}
.arrow{
          width: 20px;
          height: 20px;
}
</style>

</head>
<body>
    <div class="row base-margin" id="query">
        <ul class="breadcrumb">
       
				<li style="padding-left: 15px"><i class="icon-home home-icon"></i> <a href="javascript:void(0)">System Settings(系统设置)</a>
				</li>
				<li class="active">
				<a href="view/role/roleList.jsp">Permissions List(权限列表)</a></li>
		
	
        </ul>
        <form class="form-inline" role="form" style="float: left; width: 100%" method="post" id="queryForm">
           
           <div class="form-group">
                <label for="bName">---Role(角色):</label> 
                <input type="text" class="form-control" name="name" id="name"  >
            </div>   
            <div class="form-group">
                <button type="button" id="queryBtn" onclick="doQuery1('demo-table',queryParams1());" class="btn btn-primary">Search</button>
            </div> 
             <a  href="javascript:void(0)" onclick='add()'>
	          <span class="glyphicon glyphicon-plus addbr">Add Role </span>
	        </a>
        </form>
    </div>
    <div class="container" style="width: 100%;margin-top:15px">
        <table id="demo-table">
        </table>
    </div>
</body>
	<!-- 加载需要的js -->
	<script src="js/jquery-3.2.1.min.js"></script>
	<script src="plugin/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
	<script src="js/jquery-bootstrap-pagination.js"></script>
	<script src="plugin/bootstrap-table/dist/bootstrap-table.min.js"></script>
	<script src="plugin/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
	<script src="js/common.js"></script>
	<script src="plugin/layer/layer.js"></script>
	
	<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<script type="text/javascript" charset="utf-8">

	$(function () {
		initPath("<%=basePath%>");
	    initTable('demo-table',queryParams,columns,"role/getList");
	});
var  columns= [ { field: '', title: 'Serial Number(序号)', checkbox:true },
	 { field : 'sysRoleName',  title : 'Role Name(角色名称)',  align : 'center', valign : 'middle' },
     { field : 'actionname', title : 'Visible tabs(权限模板)', align : 'center', valign : 'middle' },
     {  field : 'upId',  title : 'Operation(操作)', align : 'center', valign : 'middle', formatter: operateFormatter  }];//自定义方法，添加操作按钮 
	
	function operateFormatter(value, row, index) {//赋予的参数	
		console.log(row);
			return [
					'<a    href="javascript:void(0)" onclick="add( \''+ row.sysRoleId+ '\',\''+ row.sysRoleName+ '\',\''+ row.actionid+ '\')" > Edit </a>',  
					 '<span> &nbsp;&nbsp; </span>',
					'<a  href="javascript:void(0)" onclick="setdelect(\''+ row.sysRoleId+ '\')" > Delete</a>'
				].join('');
		
		} 
	function add(id,name,roles){
		var title="";var str="";
		if(name==undefined){
			name="";
		}
		if(roles==undefined){
			roles="";
		}
		if(id==undefined){
			id="";
			title="Add Role";
		}else{
			title="Update Role";	
		}
		str+="<form class=\"form-horizontal\">"
		+"<div class=\"form-group\"><label  class=\"col-sm-2 control-label\" style='margin-top: 10px;width: 200px;'>Role Name(角色名称)</label>"
		+"<div class='col-sm-3'><input type='text' style='width:130px' id=\"name1\" class=\"form-control\" value='"+name+"'/>"
		+"<input type='hidden' id=\"id\"  value='"+id+"'/></div></div>"
		+"<div  style='margin-left: 37px;'><label class=\" control-label\" >Visible tabs(权限模板)</label></div>"
		+"<div style=\" margin-left: 10px; \"><span>Rider Management(乘客管理)</span>&nbsp;&nbsp;<a  data-target=\"#user\" data-toggle=\"collapse\" ><img src='images/down26.png' class='arrow' /></a></div> "
		+"<div id=\"user\" class=\"panel-collapse collapse in\">"
		+" <ul><li><input class=\"user\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"11\">Rider Management(乘客信息列表)"
		+"</li></ul></div>"
		+"<div style=\" margin-left: 10px; \"><span>Driver Management(司机管理)</span>&nbsp;&nbsp;<a  data-target=\"#vehicles\" data-toggle=\"collapse\" ><img src='images/down26.png' class='arrow' /></a></div> "
		+"<div id=\"vehicles\" class=\"panel-collapse collapse in pa\"><ul>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"21\">Driver Database(司机信息列表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"22\">Driver Online Time(司机上线时长设置)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)'  value=\"23\">Driver Cancellation Penalty(取消订单设置)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"24\">Driver Job Acceptance Radius(司机接单里程列表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"25\">Drivers Location(司机位置)</li>"
		+"</ul></div>"
		+"<div style=\" margin-left: 10px; \"><span>Vehicle Management(车辆管理)</span>&nbsp;&nbsp;<a  data-target=\"#store\" data-toggle=\"collapse\" ><img src='images/down26.png' class='arrow' /></a></div> "
		+"<div id=\"store\" class=\"panel-collapse collapse in pa\">"
		+"<ul><li> <input class=\"store\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)'  value=\"31\">Vehicle Type List(车辆信息列表)</li>"
		+"</ul></div>"
		+"<div style=\" margin-left: 10px; \"><span>Order Management(订单管理) </span>&nbsp;&nbsp;<a  data-target=\"#order\" data-toggle=\"collapse\" ><img src='images/down26.png' class='arrow' /></a></div> "
		+"<div id=\"order\" class=\"panel-collapse collapse in pa\">"
		+"<ul><li> <input class=\"order\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"41\">Completed Order List(已完成订单列表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"42\">Incomplete Order List(未完成订单列表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"43\">Driver Assistance(司机端行程反馈列表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"43\">Rider Assistance(用户行程反馈列表)</li>"
		+"</ul></div>"
		+"<div style=\" margin-left: 10px; \"><span>Finance Management(财务管理) </span>&nbsp;&nbsp;<a  data-target=\"#financial\" data-toggle=\"collapse\" ><img src='images/down26.png' class='arrow' /></a></div> "
		+"<div id=\"financial\" class=\"panel-collapse collapse in pa\">"
		+"<ul><li> <input class=\"risk\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)'  value=\"51\">Monthly Statement(月结算单订单列表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"52\">Weekly Statement(周结算单订单列表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"53\">Unpaid Payout List(未结算订单列表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"54\">Monthly report statistics(财务月报表统计)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"55\">Driver Monthly Income Table(司机月收入报表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"56\">Driver Weekly Income Table(司机周收入报表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"57\">Payout Date(结算时间设置)</li>"
		+"</ul></div>"
		+"<div style=\" margin-left: 10px; \"><span>Fare Estimation Settings(报价系统) </span>&nbsp;&nbsp;<a  data-target=\"#offer\" data-toggle=\"collapse\" ><img src='images/down26.png' class='arrow' /></a></div> "
		+"<div id=\"offer\" class=\"panel-collapse collapse in pa\">"
		+"<ul><li> <input class=\"risk\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)'  value=\"61\">Fare Settings(价格设置)</li>"
		+"<li> <input class=\"risk\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)'  value=\"62\">Toll Point Settings(收费设置)</li>"
		+"</ul></div>"
		+"<div style=\" margin-left: 10px; \"><span>Cost Management(营销管理) </span>&nbsp;&nbsp;<a  data-target=\"#marketing\" data-toggle=\"collapse\" ><img src='images/down26.png' class='arrow' /></a></div> "
		+"<div id=\"marketing\" class=\"panel-collapse collapse in pa\">"
		+"<ul><li> <input class=\"risk\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)'  value=\"71\">Issued Coupons List(优惠劵发放列表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"72\">Corporate Accounts List(企业机构信息列表)</li>"
		+"</ul></div>"
		+"<div style=\" margin-left: 10px; \"><span>System Settings(系统设置) </span>&nbsp;&nbsp;<a  data-target=\"#system\" data-toggle=\"collapse\" ><img src='images/down26.png' class='arrow' /></a></div> "
		+"<div id=\"system\" class=\"panel-collapse collapse in pa\">"
		+"<ul><li> <input class=\"risk\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)'  value=\"81\">Admin Settings(用户信息)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"82\">Permissions (职位信息列表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"83\">Staff Information List(员工信息列表)</li>"
	/* 	+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"84\">All Notifications(消息推送模板管理)</li>" */
		/* +"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"85\">Loading Page(用户启动页)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"86\">Start Page(司机启动页)</li>" */
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"87\">Version update(版本更新)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"87\">All Notifications(消息推送列表)</li>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"88\">Add bank card successful text message(添加银行卡成功短信内容)</li>"
		/* +"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"89\">司机上线时间设置</li>" */
		/* +"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"87\">建议反馈</li>" */
		+"</ul></div>"
		+"<div style=\" margin-left: 10px; \"><span>Suggestions(建议反馈) </span>&nbsp;&nbsp;<a  data-target=\"#system\" data-toggle=\"collapse\" ><img src='images/down26.png' class='arrow' /></a></div> "
		+"<div id=\"system\" class=\"panel-collapse collapse in pa\">"
		+"<ul>"
		+"<li><input class=\"vehicles\" type=\"checkbox\" name=\"check_name\" onclick='setting(this)' value=\"91\">Suggestions(建议反馈)</li>"
		+"</ul></div>"
		+"<div class=\"form-group\" style=\"padding-left: 10%\">"
		+" <button  onclick=\"return save()\" class=\"btn btn-info\"style=\"width: 200px\">保存</button><button  onclick=\"cacel()\" style=\"width: 200px;margin-left:10px\" class=\"btn btn-info\">取消</button></div></form >";
		
		layer.open({
			  type: 1,
			  title: title,
			  skin: 'layui-layer-rim', //加上边框
			  area: ['620px', '640px'], //宽高
			  content: str
			});
		setting();
		if(id!=""){
			 var radioAll  = $("input[name='check_name']");  
   	         var strs= new Array(); //定义一数组     
   	         strs=roles.split(","); //字符分割    
   	          for (var int = 0; int < strs.length; int++) {						   
   	           var authId =$.trim(strs[int]);	            
   	           	for(var a=0 ; a<radioAll.length ;a++){
   					    var radoiVal = radioAll.eq(a).val();  
   				    		    if(radoiVal == authId) {
   				    		        radioAll.get(a).checked = true;
   				    		    }
   				    		} 
   				}
		}
	}
	function setting(){
		if($(this).is(':checked')){
			$(this).prop("checked",true);
		}else{
			$(this).prop("checked",false);
		}

	}
	function cacel(){
		layer.closeAll();
	}
	
	function queryParams(params) {
		 console.log(params);  
	    var param = {
	    		name:$('#name').val(),
	        pageNumber : this.pageNumber,
	        pageSize : this.pageSize
	    }	
	    return param;
	} 
	function queryParams1(params) {
		 console.log(params);  
	    var param = {
	    		name:$('#name').val(),
	        pageNumber : this.pageNumber,
	        pageSize : this.pageSize
	    }	
	    return param;
	}
			function  setdelect(id){		        
				var  flag =  confirm("Are you sure you want to delete?");				
				  if(flag){
						 $.ajax({
					            type: "get",
					            url: "role/delete",
					            dataType:"json",
					            data:{"id":id},
					            success: function(data){    
					           	  console.log(data)
					          	  if(data.code==200){	 
					          		doQuery1('demo-table',queryParams());
						        	 }else{
						        		  layer.msg(data.msg); 
						        	 }
					       }
					        }); 
				  }
				
			 }
		
			
			//保存
	function save(){
		var id=$('#id').val();
		var name=$('#name1').val();
			  var checkArray  =  $("input:checkbox[name='check_name']:checked");					  		  
			        var str =new Array();
			        var str1 =new Array();
		            for (var i = 0; i < checkArray.length; i++) {
		            	str.push(checkArray[i].value);		 
		            	str1.push(checkArray[i].nextSibling.data); 
			    } 
		        var roles = str.join(',');   
		        var rName=str1.join(',');   
		        if(name==""){
		        	layer.msg("Rule Name cannot be empty");
		        	return false;
		        }
		        if(roles==""){
		        	layer.msg("Permissions cannot be empty ");
		        	return false;
		        } 
        var data={"sysRoleName":name,"actionid":roles,"sysRoleId":id,"actionname":rName};
      		 $.ajax({
                   type: "post",
                   url: "role/addOrUpdate",
                   data: JSON.stringify(data),
                   contentType:"application/json;charset=UTF-8", 
                   dataType:"json",
                   success: function(data){    	            	 
                  if(data.code==200){
                  	 window.location.reload();    
            	       }else{
            	    	    layer.msg(data.msg);
            	       }
                            }
               }); 
      		return false;
	}
	
	
	 
	</script>
</html>


